<?php
include("controller.php");
include(MODELDIR."category.php");
class CategoryController extends Controller 
{
	private  $cate;
	public function init()
	{
		$this->cate=new Category();
	}
	public function indexAction()
	{	
		$this->view->cates=$this->cate->getAllCategory();
		$this->display();
	}
	
	public function newAction()
	{
		if($_POST)
		{
			$this->cate->setData($_POST);
			$this->cate->insert();
			header("Location:".BASEURL.$this->getModuleName()."/".$this->getControllerName());
		}
		$this->display("new");
	}
	
	public function deleteAction($cate_id)
	{
		$this->cate->delete("id=$cate_id");
		header("Location:".BASEURL.$this->getModuleName()."/".$this->getControllerName());
	}
	
	public function editAction($cate_id)
	{
		$this->cate->findById($cate_id);
		if($_POST)
		{
			$_POST["id"]=$cate_id;
			$this->cate->setData($_POST);
			$this->cate->save();
			header("Location:".BASEURL.$this->getModuleName()."/".$this->getControllerName());
		}
		$this->view->cate=$this->cate;
		
		$this->display("new");
	}
}